package boot.spring.config;


import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import org.springframework.beans.factory.annotation.Value;

public class ConnectionUtil {

    @Value("${spring.rabbitmq.host}")
    private static String  ip ;
    @Value("${spring.rabbitmq.port}")
    private static  Integer  port ;
    @Value("${spring.rabbitmq.password}")
    private static String  password ;
    @Value("${spring.rabbitmq.username}")
    private static String  username ;

    public static Connection getConnection() throws Exception {
        //定义连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //设置服务地址
        factory.setHost( "1.15.67.211" );
        //端口
        factory.setPort( 5672 );
        //设置账号信息，用户名、密码、vhost
     //   factory.setVirtualHost(virtualhost);
        factory.setUsername("tiger");
        factory.setPassword("tiger@123" );
        // 通过工程获取连接
        Connection connection = factory.newConnection();
        return connection;
    }
}

